/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package admin.controller;



import admin.action.ActionAdd;
import admin.action.ActionUpdate;
import admin.action.IAction;
import admin.provider.ActivityProvider;
import admin.provider.WrapperProvider;
import ejb.entity.Activity;
import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.faces.view.ViewScoped;
import javax.inject.Named;

/**
 *
 * @author Nothing4ever
 */
@Named(value = "activityDetailController")
@ViewScoped
public class ActivityDetailController extends WrapperInforController<Activity> implements Serializable {

    private static final long serialVersionUID = 1L;
    private Activity activity;
    private IAction<Activity> action;

    public ActivityDetailController() {
//        checkInputData();
    }

    
    @Override
    public Activity getObject() {
        return activity;
    }

    @Override
    public WrapperProvider<Activity> getProvider() {
        return ActivityProvider.getInstance();
    }

    @Override
    public IAction<Activity> getAction() {
        return action;
    }
    
    @PostConstruct
    private void checkInputData() throws NumberFormatException {
        String strCityId = getCommonUtils().getRequestParameter("id");
        if (getStringUtil().isEmpty(strCityId)) {
            activity = new Activity();
            action = new ActionAdd<>(getProvider(), activity);
        } else {
            activity = getProvider().findById(new Integer(strCityId));
            if (activity == null) {
                getCommonUtils().redirectPage("list.xhtml");
            } else {
                action = new ActionUpdate<>(getProvider(), activity);
            }
        }
    }
}
